// pages/check/check.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		state: '',
		http:getApp().globalData.map
	},
	onShow: function() {
		let that=this
		wx.getStorage({
			key: 'uid',
			success: (res) => {
				this.setData({
					uid: res.data
				})
				console.log(res.data.group_id)
				if(res.data.group_id==1){
					wx.request({
						url: getApp().globalData.http + 'action=applySearch&uid=' + that.data.uid.uid,
						success: (e) => {
							console.log(e)
							let v = e.data.data
							let a = ''
							if (v.userType == 1) {
								if (v.changjia == 0) {
									a = 1
								} else if (v.jishi == 0) {
									a = 2
								} else if (v.xiulichang == 0) {
									a = 3
								} else {
									a = 0
								}
							} else {
								var key = ''
								var state = ''
								wx.getStorage({
									key: 'key',
									success: (e) => {
										key = e.data
										wx.getStorage({
											key: 'state',
											success: (e) => {
												state = e.data
												wx.request({
													url: getApp().globalData.http + "action=wxLogin&skey=" + key + "&encryptedData=" +
														state.encryptedData + "&iv=" + state.iv,
													success: function(e) {
														console.log(e)
														wx.setStorage({
															key: 'user',
															data: e.data.data,
														})
														wx.request({
															url: getApp().globalData.http + "action=wxlogin&unionid=" + e.data.data.unionId,
															success: function(res) {
																console.log(res)
																wx.setStorage({
																	key: 'uid',
																	data: res.data.data,
																})
																wx.switchTab({
																	url: '../index/index'
																})
															}
														})
													}
												})
											}
										})
									}
								})
							}
							that.setData({
								data: e.data.data,
								state: a,
								zt:res.data.group_id
							})
						}
					})
				}else if(res.data.group_id==2){
					that.setData({
						zt:res.data.group_id
					})
				}else if(res.data.group_id==3){
					wx.request({
						url:getApp().globalData.chang+'action=index&uid='+that.data.uid.uid,
						success: (e) => {
							console.log(e)
							this.setData({
								data:e.data.data,
							})
						}
					})
					that.setData({
						zt:res.data.group_id
					})
				}else if(res.data.group_id==4){
					console.log(this.data.uid)
					wx.request({
						url:getApp().globalData.http1+'action=index&uid='+that.data.uid.uid,
						success: (e) => {
							console.log(e)
							this.setData({
								data:e.data.data,
							})
						}
					})
					that.setData({
						zt:res.data.group_id
					})
				}
			},
			fail: (e) => {
				wx.redirectTo({
					url: '../logs/logs'
				})
			}
		})
	},
	wd(){
		if (this.data.state == 3 || this.data.state == 0) {
			if (this.data.data.xiulichang == 3) {
				wx.navigateTo({
					url: 'shop/shop'
				})
			} else if (this.data.data.xiulichang == 0) {
				wx.navigateTo({
					url: 'audit/audit'
				})
			} else if (this.data.data.xiulichang == 2) {
				wx.navigateTo({
					url: 'defeated/defeated?id=2'
				})
			}
		} else {
			if(this.data.zt==2){
				wx.showToast({
					icon: 'none',
					title: '您已成为技师'
				})
			}else{
				wx.showToast({
					icon: 'none',
					title: '您已经提交其他申请'
				})
			}
		}
	},
	gys() {
		if (this.data.state == 1 || this.data.state == 0) {
			if (this.data.data.changjia == 3) {
				wx.navigateTo({
					url: 'gysenter/gysenter?id=3'
				})
			} else if (this.data.data.changjia == 0) {
				wx.navigateTo({
					url: 'audit/audit'
				})
			} else if (this.data.data.changjia == 2) {
				wx.navigateTo({
					url: 'defeated/defeated?id=3'
				})
			}
		} else {
			if(this.data.zt==2){
				wx.showToast({
					icon: 'none',
					title: '您已成为技师'
				})
			}else{
				wx.showToast({
					icon: 'none',
					title: '您已经提交其他申请'
				})
			}
		}
	},
	getScancode: function() {
	    var _this = this;
	    // 允许从相机和相册扫码
	    wx.scanCode({
	      success: (res) => {
			  console.log(res.result.split('&'))
			  let a=res.result.split('&')
			  if(a.length<2){
				  wx.showToast({
					  icon:'none',
					  title:'二维码错误'
				  })
			  }else{
				  wx.request({
					  url:getApp().globalData.chang+'action=saomahexiao&orderCode='+a[0]+'&ItemID='+a[1]+'&uid='+_this.data.uid.uid,
					  success:(e)=>{
						  console.log(e)
						  wx.showToast({
							  icon:'none',
							  title:e.data.msg
						  })
					  }
				  })
			  }
	      }
	    })
	  },
	  jishi(){
		  if (this.data.state == 2 || this.data.state == 0) {
		  	if (this.data.data.jishi == 3) {
		  		wx.navigateTo({
		  			url: 'jishi/jishi?id=1'
		  		})
		  	} else if (this.data.data.jishi == 0) {
		  		wx.navigateTo({
		  			url: 'audit/audit'
		  		})
		  	} else if (this.data.data.jishi == 2) {
		  		wx.navigateTo({
		  			url: 'defeated/defeated?id=1'
		  		})
		  	}
		  } else {
		  	if(this.data.zt==2){
		  		wx.showToast({
		  			icon: 'none',
		  			title: '您已成为技师'
		  		})
		  	}else{
		  		wx.showToast({
		  			icon: 'none',
		  			title: '您已经提交其他申请'
		  		})
		  	}
		  }
	  }
})
